package com.zrar.easyweb.demo.uc;

import com.google.common.base.Predicates;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 服务启动入口
 *
 * @author green
 * @date 2019/10/15
 * @company 安人股份
 * @desc
 */
@SpringCloudApplication
@Configuration
@MapperScan("com.zrar.easyweb.demo.uc.dao")
@EnableSwagger2
public class UCApplication {

    public static void main(String[] args) {
        SpringApplication.run(UCApplication.class, args);
    }


    /**
     * Swagger文档配置，屏蔽了与接口无关的其他接口信息，补充了项目名称、版本等信息
     *
     * @return
     */
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .pathMapping("/").select().apis(RequestHandlerSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .paths(Predicates.not(PathSelectors.regex("/actuator.*")))
                .paths(PathSelectors.regex("/.*"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("用户服务")
                .description("提供用户、机构、部门等数据的管理服务")
                .termsOfServiceUrl("http://www.zrar.com")
                .version("v1.0")
                .build();
    }


}
